package dao

import (
	"sync"
	"time"
)

type User struct {
	ID          int64     `gorm:"column:id"`
	StuId       string    `gorm:"stu_id"`
	Password    string    `gorm:"password"`
	GMTCreated  time.Time `gorm:"-"`
	GMTModified time.Time `gorm:"-"`
}

func (User) TableName() string {
	return "user"
}

type UserDao struct {
}

var UserDaoInstance *UserDao
var UserOnce sync.Once

func GetUserDaoInstance() *UserDao {
	UserOnce.Do(
		func() {
			UserDaoInstance = &UserDao{}
		})
	return UserDaoInstance
}

func (u *UserDao) Query(stuId string) (*User, error) {
	var User *User
	err := DBClient.Where("stu_id=?", stuId).First(&User).Error
	if err != nil {
		return nil, err
	}
	return User, nil
}
